package edu.mse.camel.client.uml.collab.editor;

import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

import com.cea.papyrus.core.actions.ExtendedActionRegistry;
import com.cea.papyrus.core.treeeditpart.TreeOutlinePage;
import com.cea.papyrus.diagram.sequence.SequenceDiagramEditor;
import edu.mse.camel.client.log.Debug;
import edu.mse.camel.client.uml.collab.CollabPlugin;

public class CollabSequenceDiagramEditor extends SequenceDiagramEditor {
	
	public static final String ID = "edu.mse.camel.client.uml.collab.editor.sequence";
	
	public CollabSequenceDiagramEditor() {
		setEditDomain(new DefaultEditDomain(this));
		this.actionRegistry = 
			new ExtendedActionRegistry(EditorUtil.createParentRegistry(this));
	}
	
	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		CollabEditorInput cei = (CollabEditorInput) input;
		this.modelMngr = cei.getModelManager();
		this.diagram = cei.getDiagram();
		setTitleToolTip(diagram.getName());
		
		this.getEditDomain().setCommandStack(new CamelCommandStack(modelMngr, ((CollabEditorInput)input).isSource()));
		
		super.init(site, input);
		
		Debug.log_info(CollabPlugin.PLUGIN_ID, "Sequence has bee created");
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object getAdapter(Class adapter) {
		if (adapter == IContentOutlinePage.class) {
			// return new com.cea.papyrus.core.common.treeeditpart.TreeOutlinePage(new TreeViewer(), getEditDomain(), (ActionRegistry)this.getAdapter(ActionRegistry.class), getSelectionSynchronizer(),modelManager);
			return new TreeOutlinePage(
					new TreeViewer(), 
					getEditDomain(), 
					(ActionRegistry) this.getAdapter(ActionRegistry.class), 
					null, 
					modelMngr);
		}
		return super.getAdapter(adapter);
	}
	
}
